home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / fvecx.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  1KB  |  58 lines

  1. /*
  2.  *    Type specific routines for FloatVec
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)fvecx.cc    2.1    8/18/89
  23.  */
  24.  
  25.  
  26. #define NO_VECTOR_MATHFUN
  27. #include "rw/FloatVec.h"
  28. #include "rw/DoubleVec.h"
  29.  
  30. // Construct from DoubleVec     
  31. FloatVec::FloatVec(const DoubleVec& v)
  32. {
  33.   register int n = npts = v.length();
  34.   block = new FloatBlock(n);
  35.   register float* tp = begin = block->data();
  36.   register double* dp = v.data();
  37.   register int ds = v.stride();
  38.   while(n--){
  39.     *tp++ = float(*dp); dp += ds;
  40.   }
  41.   step = 1;
  42. }
  43.  
  44. // Convert to DoubleVec.  
  45. // Should be a friend, but.... 
  46. FloatVec::operator DoubleVec()
  47. {
  48.   register int n = length();
  49.   DoubleVec temp(n);
  50.   register double* dp = temp.data();
  51.   register float* tp = data();
  52.   register int ts = stride();
  53.   while(n--) {
  54.     *dp++ = double(*tp); tp += ts;
  55.   }
  56.   return temp;
  57. }
  58.